package com.sgcc.pda.h5.dialog;

import android.content.Context;

import com.sgcc.pda.sdk.utils.DialogUtil;
import com.sgcc.pda.sdk.utils.dialog.AlterDialog;
import com.sgcc.pda.sdk.utils.dialog.ConfirmDialog;
import com.sgcc.pda.sdk.utils.dialog.DialogLoadingFMV4;

/**
 * @author superFan
 * date: 2019/7/25/025 22:22
 * Copyright (c) 2019 hezhongweiqi.Co.Ltd. All rights reserved.
 * description: 供H5使用的统一弹窗工具类，其根本使用的sdk中的DialogUtil
 */
public class DialogH5Util {

    private DialogLoadingFMV4 progressDialogV4;

    private DialogH5Util() {
    }

    private Context mContext;

    public static class Instance {
        private static final DialogH5Util INSTANCE = new DialogH5Util();
    }

    public static DialogH5Util getInstance() {
        return Instance.INSTANCE;
    }

    public void init(Context context) {
        mContext = context;
    }

    /**
     * 只带有确认按钮的信息提示框
     *
     * @param title                  标题
     * @param msg                    信息
     * @param canceledOnTouchOutside 是否点击外围可以取消
     * @param okListener             确认按钮的监听
     */
    public void warnNotice(String title, String msg, boolean canceledOnTouchOutside, AlterDialog.IOkClickedListener okListener) {
        DialogUtil.alter(mContext, title, msg, "确定", true, canceledOnTouchOutside, okListener);
    }

    /**
     * 带有确认和取消按钮的信息提示框 （左取消，右确认）
     *
     * @param title                  标题
     * @param msg                    信息
     * @param canceledOnTouchOutside 是否点击外围可以取消
     * @param okListener             确认按钮的监听
     */
    public void confirmNotice(String title, String msg, boolean canceledOnTouchOutside, ConfirmDialog.IOkClickedListener okListener, ConfirmDialog.ICancelClickedListener cancelListener) {
        DialogUtil.confirm(mContext, title, msg, "确定", "取消", false, canceledOnTouchOutside, okListener);
    }

    /**
     * 显示加载框
     *
     * @param msg
     */
    public void showLoading(String msg) {
        if (progressDialogV4 == null) {
            progressDialogV4 = DialogUtil.getProgressDialogV4(mContext, msg);
        }
        DialogUtil.show(mContext, progressDialogV4);
    }

    /**
     * 隐藏加载框
     */
    public void hideLoading() {
        if (progressDialogV4 != null && mContext != null) {
            DialogUtil.dismiss(mContext, progressDialogV4);
        }
    }

}
